package com.example.himalaya.view_component;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.himalaya.R;

public class ConfirmDialog extends Dialog {

    private TextView mRightBtn;
    private TextView mLeftBtn;
    private onDialogActionClickListener mClickListener = null;

    public ConfirmDialog(@NonNull Context context) {
        this(context, 0);
    }

    public ConfirmDialog(@NonNull Context context, int themeResId) {
        this(context, true, null);
    }

    protected ConfirmDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_confirm);

        initView();

        initListener();
    }

    private void initListener() {
        mLeftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mClickListener != null) {
                    mClickListener.onLeftBtnClick();
                }

                dismiss();
            }
        });

        mRightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mClickListener != null) {
                    mClickListener.onRightBtnClick();
                }

                dismiss();
            }
        });
    }

    private void initView() {
        mRightBtn = this.findViewById(R.id.dialog_right_lv);

        mLeftBtn = this.findViewById(R.id.dialog_left_lv);
    }

    public void setonDialogActionClickListener(onDialogActionClickListener listener) {
        this.mClickListener = listener;
    }

    public interface onDialogActionClickListener {
        void onRightBtnClick();

        void onLeftBtnClick();
    }
}
